package com.stu.reflection.unsafe_singleton;

import sun.misc.Unsafe;

//单例类
public class Singleton {
  private Singleton() { System.out.println("***单例构造***"); }

  public static Singleton getInstance() throws InstantiationException {
    Unsafe unsafe = UnsafeUtil.getUnsafe();
    //利用Unsafe类绕过JVM的管理机制，可以在没有调用构造方法的情况下获取一个Singleton类实例化对象
		return (Singleton)unsafe.allocateInstance(Singleton.class);
  }

	public void print() { System.out.println("hello unsafe"); }
}
